/**
 * @author :    hippo
 * @date :      2023-07-30
 * @copyright   Apache 2.0
*/

#ifndef _SQLCONNRAII_H
#define _SQLCONNRAII_H

#include <assert.h>
#include "sql_conn_pool.h"

class SqlConnRAII {
private:
    MYSQL *sql_;
    SqlConnPool *connpool_;
public:
    SqlConnRAII(MYSQL **sql, SqlConnPool *connpool) {
        assert(connpool);
        *sql = connpool->GetConn();
        sql_ = *sql;
        connpool_ = connpool;
    }

    ~SqlConnRAII() {
        if(sql_) {
            connpool_->FreeeConn(sql_);
        }
    }
};

#endif // _SQLCONNRAII_H